//
//  WoDeViewController.m
//  JuBoCRM
//
//  Created by iMac on 2024/1/24.
//  Copyright © 2024 iningKe. All rights reserved.
//

#import "WoDeViewController.h"
#import "BianJiZiLiaoViewController.h"
#import "SheZhiViewController.h"
#import "ZBNetworking.h"
#import "DaiBanShiXiangViewController.h"
@interface WoDeViewController ()
@property (weak, nonatomic) IBOutlet UIView *geRenBackView;
@property (weak, nonatomic) IBOutlet TPKeyboardAvoidingScrollView *mainScrollView;
@property (weak, nonatomic) IBOutlet UIImageView *headImageLabel;
@property (weak, nonatomic) IBOutlet UILabel *buMenLabel;

@property (weak, nonatomic) IBOutlet UITextField *nameLabel;
@end

@implementation WoDeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.customNavBar.title = @"个人中心";
    self.customNavBar.titleLable.textColor = [UIColor whiteColor];
    [self.customNavBar wr_setBackgroundAlpha:0];
    
    if (@available(iOS 11.0, *)) {
        self.mainScrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }
    
    [self addCodeButtonLayer];
    
    [self getInfoFromServerAndNeedLoad:YES];
    
    

}


- (void)getInfoFromServerAndNeedLoad:(BOOL)load{
    [[ZZPRequest getWebUtil] postJsonNetworkRequestURLString:@"/adminUser/queryLoginUser" andParas:nil andShowHud:YES andTransferGottenData:^(id info, NSError *error) {
        if(!error){
            NSLog(@"%@",info);
            
            [ZZPUtils saveUserDefultsData:[ZZPUtils deleteEmpty:[info objectForKey:@"data"]] forKey:@"userInfo"];
            
            _nameLabel.text = GetHandleString(USERINFO, @"realname");
            _buMenLabel.text = GetHandleString(USERINFO, @"deptName");

            [_headImageLabel sd_setImageWithURL:WebImagePath(GetHandleString(USERINFO, @"urlImage")) placeholderImage:HeadImagePlaceholder];
        }
    }];
}

- (void)addCodeButtonLayer{
    // gradient
    CAGradientLayer *gl = [CAGradientLayer layer];
    gl.frame = CGRectMake(0,0,ScreenWidth-32,120);
    gl.startPoint = CGPointMake(0.5, 0);
    gl.endPoint = CGPointMake(0.61, 0.96);
    gl.colors = @[(__bridge id)rgba(194, 217, 252, 1).CGColor, (__bridge id)rgba(255, 255, 255, 1).CGColor];
    gl.locations = @[@(0), @(1.0f)];
    [_geRenBackView.layer insertSublayer:gl atIndex:0];
    _geRenBackView.layer.cornerRadius = 10;
    _geRenBackView.layer.shadowColor = rgba(172, 78, 15, 0.16).CGColor;
    _geRenBackView.layer.shadowOffset = CGSizeMake(0,1.5);
    _geRenBackView.layer.shadowOpacity = 1;
    _geRenBackView.layer.shadowRadius = 3;
}

//个人资料
- (IBAction)geRenZiLiao:(UITapGestureRecognizer *)sender {
    
    BianJiZiLiaoViewController *ziLiao = [[BianJiZiLiaoViewController alloc] init];
    ziLiao.changeBlock = ^(UIImage * _Nonnull image) {
        if(image != nil){
            _headImageLabel.image = image;
        }else{
            [self getInfoFromServerAndNeedLoad:NO];
        }
    };
    ziLiao.image = _headImageLabel.image;
    [self pushViewController:ziLiao];
}

//待办事项
- (IBAction)daiBan:(UITapGestureRecognizer *)sender {
    DaiBanShiXiangViewController *danBan = [[DaiBanShiXiangViewController alloc] init];
    [self pushViewController:danBan];
}

//设置
- (IBAction)sheZhi:(UITapGestureRecognizer *)sender {
    SheZhiViewController *sheZhi = [[SheZhiViewController alloc] init];
    [self pushViewController:sheZhi];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
